/*
 * @Description:
 * @Author:
 * @Date: 2024-12-07 09:16:40
 * @LastEditTime: 2024-12-07 22:44:35
 * @LastEditors: XXX
 */
import type { Module, Store as VuexStore, CommitOptions, DispatchOptions } from 'vuex'
import type { UserState } from './state'
import type { RootState } from '@/store'
import type { Actions } from './actions'
import type { Mutations } from './mutations'

import { state } from './state'
import { mutations } from './mutations'
import { actions } from './actions'

export type { UserState }

export type UserStore<S = UserState> = Omit<VuexStore<S>, 'getters' | 'commit' | 'dispatch'> & {
  commit<K extends keyof Mutations, P extends Parameters<Mutations[K]>[1]> (
    key: K,
    payload: P,
    options?: CommitOptions
  ): ReturnType<Mutations[K]>
} & {
  dispatch<K extends keyof Actions> (
    key: K,
    payload?: Parameters<Actions[K]>[1],
    options?: DispatchOptions
  ): ReturnType<Actions[K]>
}

export const store: Module<UserState, RootState> = {
  state,
  mutations,
  actions
}
